<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fm" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>商品</title>
    <link href="../css/table.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../js/jquery-1.11.1.js"></script>
    <script type="text/javascript" src="../js/table.js"></script>
</head>

<style type="text/css">
    #header, #content {
        width: 99%;
    }
    .anniu {
        margin-left: 500px;
    }
</style>

<script type="text/javascript">
    function edit() {
        var radios = document.getElementsByName("choosen");
        var id = "";
        for (var i = 0; i < radios.length; i++) {
            if (radios[i].checked == true) {
                id = radios[i].value;
                break;
            }
        }
        if (id == "") {
            alert("请选择需要操作的商品");
        } else {
//            document.getElementById("id").value = id;
            document.operationForm.action = "${pageContext.request.contextPath}/product/findProductById.action?id="+id;
            document.operationForm.submit();
        }
    }

    function delete1() {
        var radios = document.getElementsByName("choosen");
        var id = "";
        for (var i = 0; i < radios.length; i++) {
            if (radios[i].checked == true) {
                id = radios[i].value;
                break;
            }
        }
        if (id == "") {
            alert("请选择需要操作的商品");
        } else if (confirm('确认删除吗？')) {
            document.getElementById("id").value = id;
            document.operationForm.action = "${pageContext.request.contextPath}press/deletePress";
            document.operationForm.submit();
        }
    }

    function add() {
        window.location.href = '${pageContext.request.contextPath}press/toAddPress';
    }

    function allList() {
        window.location.href = '${pageContext.request.contextPath}/product/findAllProducts.action';
    }

    function deleteProducts(){
        document.operationForm.action="${pageContext.request.contextPath}/product/deleteProducts.action";
        document.operationForm.submit();
    }

    function queryProduct(){
        document.operationForm.action="${pageContext.request.contextPath}/product/findProductByName.action";
        document.operationForm.submit();
    }

    function editProductsList(){
        document.operationForm.action="${pageContext.request.contextPath}/product/productListEdit.action";
        document.operationForm.submit();
    }

    function editProductsMap(){
        document.operationForm.action="${pageContext.request.contextPath}/product/productMapEdit.action";
        document.operationForm.submit();
    }

</script>

<body>
当前用户${username},
<c:if test="${username!=null}">
    <a href="${pageContext.request.contextPath}/logout">退出</a>
</c:if>
<h2>商品列表</h2>

    <form name="operationForm" action="" method="post" class="anniu">
        查询条件:
        商品名称:<input type="text" name="productAndUser.name"/>
        <input type="button" onclick="javascript:queryProduct()" value="按商品名查询"/>
        商品类型:
        <select name="productType">
            <c:forEach var="productType" items="${productTypes1}">
                <option value="${productType.key}">${productType.value}</option>
            </c:forEach>
        </select>
        <br>
        <input type="hidden" id="id" name="id" value="">
        <input type="button" onclick="javascript:add()" value="新增">
        <input type="button" onclick="javascript:edit()" value="修改">
        <input type="button" onclick="javascript:delete1()" value="删除">
        <input type="button" onclick="javascript:deleteProducts()" value="批量删除" />
        <input type="button" onclick="javascript:editProductsList()" value="批量修改List类型实现" />
        <input type="button" onclick="javascript:editProductsMap()" value="批量修改Map类型实现" />
        <input type="button" onclick="javascript:allList()" value="所有商品">

        <table >
            <tr>
                <th>修改</th>
                <th>批量删除</th>
                <th>商品编号</th>
                <th>商品名</th>
                <th>价格</th>
                <th>详情</th>
                <th>创建日期</th>
            </tr>
            <c:forEach var="list" items="${lists}">
                <tr>
                    <td><input type="radio" name="choosen" value="${list.id}"></td>
                    <td><input type="checkbox" name="items_id" value="${list.id}"></td>
                    <td>${list.id}</td>
                    <td>${list.name}</td>
                    <td>${list.price}</td>
                    <td>${list.detail}</td>
                    <td><fm:formatDate value="${list.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                </tr>
            </c:forEach>
        </table>

    </form>
</body>
</html>

